<template>
    <view>
		<u-input v-model="content" :border="true" confirm-type="search" @confirm="saveComment(flag)"/>
        <view class="uni-padding-wrap">
            <!-- 评论区 start -->
            <view class="uni-comment">
                <view class="uni-comment-list" v-for="(item, index) in list" :key="index">
                    <view class="uni-comment-face">
                        <image src="../../static/avatar@2x.png" mode="widthFix"></image>
                    </view>
                    <view class="uni-comment-body">
                        <view class="uni-comment-top">
                            <text>{{ item.creatorName }}</text>
                        </view>
                        <view class="uni-comment-date">
                            <text>{{ item.createDate }}</text>
                        </view>
                        <view class="uni-comment-content">{{ item.remark }}</view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
	import {
		getPetSendComment,
		savePetSendComment,
		getPetLostComment,
		savePetLostComment,
		getPetTeamComment,
		savePetTeamComment
	} from '@/api/comment/comment.js'
    export default {
        data() {
            return {
				id: '',
				flag: '',
				content: '',
                list: []
            }
        },
		methods: {
			getData(id, flag) {
				if (flag === 0) {
					getPetSendComment(id).then(res => {
						if (res.code == 0) {
							this.list = res.data
						}
					})
				}
				if (flag === 1) {
					getPetLostComment(id).then(res => {
						if (res.code == 0) {
							this.list = res.data
						}
					})
				}
				if (flag === 2) {
					getPetTeamComment(id).then(res => {
						if (res.code == 0) {
							this.list = res.data
						}
					})
				}
			},
			saveComment(flag) {
				if (flag === 0) {
					savePetSendComment(this.id, this.content).then(res => {
						if (res.code == 0) {
							uni.showToast({
								title: '留言成功！',
								icon: 'success'
							});
							this.content = ''
							this.getData(this.id, flag)
						}
					})
				}
				if (flag === 1) {
					savePetLostComment(this.id, this.content).then(res => {
						if (res.code == 0) {
							uni.showToast({
								title: '留言成功！',
								icon: 'success'
							});
							this.content = ''
							this.getData(this.id, flag)
						}
					})
				}
				if (flag === 2) {
					savePetTeamComment(this.id, this.content).then(res => {
						if (res.code == 0) {
							uni.showToast({
								title: '留言成功！',
								icon: 'success'
							});
							this.content = ''
							this.getData(this.id, flag)
						}
					})
				}
			}
		}
    }
</script>

<style>
    /* comment */
    page {
        background-color: #f8f8f8;
    }

    .uni-padding-wrap {
        /* padding: 10rpx; */
    }

    view {
        font-size: 28upx;
    }

    .uni-comment {
        padding: 5rpx 0;
        display: flex;
        flex-grow: 1;
        flex-direction: column;
    }

    .uni-comment-list {
        flex-wrap: nowrap;
        padding: 10rpx 0;
        margin: 10rpx 0;
        width: 100%;
        display: flex;
    }

    .uni-comment-face {
        width: 70upx;
        height: 70upx;
        border-radius: 100%;
        margin-right: 20upx;
        flex-shrink: 0;
        overflow: hidden;
    }

    .uni-comment-face image {
        width: 100%;
        border-radius: 100%;
    }

    .uni-comment-body {
        width: 100%;
    }

    .uni-comment-top {
        line-height: 1.5em;
        justify-content: space-between;
    }

    .uni-comment-top text {
        color: #0A98D5;
        font-size: 24upx;
    }

    .uni-comment-date {
        line-height: 38upx;
        flex-direction: row;
        justify-content: space-between;
        display: flex !important;
        flex-grow: 1;
    }

    .uni-comment-date view {
        color: #666666;
        font-size: 24upx;
        line-height: 38upx;
    }

    .uni-comment-content {
        line-height: 1.6em;
        font-size: 28upx;
        padding: 8rpx 0;
    }

    .uni-comment-replay-btn {
        background: #FFF;
        font-size: 24upx;
        line-height: 28upx;
        padding: 5rpx 20upx;
        border-radius: 30upx;
        color: #333 !important;
        margin: 0 10upx;
    }
</style>
